package cn.dnui_xqh414.dnuifood_16110100414.Fragment;


import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import cn.dnui_xqh414.dnuifood_16110100414.R;
import cn.dnui_xqh414.dnuifood_16110100414.bean.ShopdetailBean;
import cn.dnui_xqh414.dnuifood_16110100414.fragment_adapter_and_vhoder.rv_Adapter_shopList;
import cn.dnui_xqh414.dnuifood_16110100414.listener.OnRetrofitListener;
import cn.dnui_xqh414.dnuifood_16110100414.model.FoodlistModel;

/**
 * A simple {@link androidx.fragment.app.Fragment} subclass.
 */
public class ShopFoodListFragment
        extends androidx.fragment.app.Fragment
        implements OnRetrofitListener<List<ShopdetailBean>> {

    private RecyclerView recyclerView;
    private List<ShopdetailBean> list;
    private rv_Adapter_shopList adapter_shopList;



    public ShopFoodListFragment() {
        // Required empty public constructor

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_shop_food_list, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        FoodlistModel foodlistModel = new FoodlistModel();
        foodlistModel.getFoodlist(String.valueOf(getActivity().
                getIntent().getIntExtra("shopid",-1)),this);

        recyclerView = getView().findViewById(R.id.rv_shop_food_list);

        RecyclerView.LayoutManager layoutManager =
                new LinearLayoutManager(getContext());

        recyclerView.setLayoutManager(layoutManager);

        recyclerView.setHasFixedSize(true);

        String phonenum = getActivity().getIntent().getStringExtra("phonenum");
        adapter_shopList = new rv_Adapter_shopList(getContext(),phonenum);
        recyclerView.setAdapter(adapter_shopList);
    }

    @Override
    public void onSuccess(List<ShopdetailBean> object, int flag) {
        if (flag == 1)
        list = object;
        adapter_shopList.setList(list);
    }

    @Override
    public void onFailure(String msg) {

    }



}
